import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBGongGongCreateTimeModel.dart';

import 'YBMiShuProvider/YBMiShuProvider.dart';
import 'YBMiShuSubPage/YBMiShuTongListDetailSubPage.dart';


class YBMiShuListDetailYouXuanShangJiPage extends StatefulWidget {

  final String sysCode;
  final String requestCode;

  const YBMiShuListDetailYouXuanShangJiPage({Key key, this.sysCode, this.requestCode}) : super(key: key);

  @override
  _YBMiShuListDetailYouXuanShangJiPageState createState() => _YBMiShuListDetailYouXuanShangJiPageState(sysCode: sysCode,requestCode: requestCode);
}

class _YBMiShuListDetailYouXuanShangJiPageState extends State<YBMiShuListDetailYouXuanShangJiPage> {

  final String sysCode;
  final String requestCode;

  _YBMiShuListDetailYouXuanShangJiPageState({this.sysCode, this.requestCode});

  bool _select = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text(
            YBChineseText.workTaiShangJiDetailTitle,
            style: YBTextStyle.TextStyle30313320Medium
          ),
        ),
        body:MultiProvider(
          providers:[
            ChangeNotifierProvider(create: (context)=>YBGongGongYouXuanRealDetailProvider()..getGongGongYouXuanDataList(sysCode, requestCode)),
            ChangeNotifierProvider(create: (context)=>YBGongGongShengYuNumberProvider()..getGongGongYouXuanDataList(sysCode)),
            ChangeNotifierProvider(create:(context)=>YBGongGongQiangDuoProvider()),
          ],
          child: Consumer<YBGongGongYouXuanRealDetailProvider>(
             builder: (context,youXuanInfo,child){
               Widget bottomWidget;
               if((DateTime.now().millisecondsSinceEpoch) - (DateTime.parse(youXuanInfo.gongGongYouXuanModel.createTime).millisecondsSinceEpoch) > 3600*24*1000){
                 bottomWidget = Column(
                   mainAxisAlignment: MainAxisAlignment.start,
                   crossAxisAlignment: CrossAxisAlignment.stretch,
                   children: [
                     Container(
                       height: YBTextStyle.adapterSize15,
                     ),
                     Container(
                       height: YBTextStyle.adapterSize44,
                       child: Padding(
                         padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                         child: FlatButton(
                           shape: RoundedRectangleBorder(
                             side: BorderSide.none,
                             borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize8)),
                           ),
                           color: YBColor.color7A7A7A,
                           child: Text(YBChineseText.workTaiYuQiShangJiTitle,style: YBTextStyle.xieGangQingNianTuiGuangYuanBtnText,),
                           onPressed:(){},
                         ),
                       ),
                     ),
                     Container(
                       height: YBTextStyle.adapterSize15,
                     ),
                   ],
                 );
               }else{
                 bottomWidget = Column(
                   mainAxisAlignment: MainAxisAlignment.start,
                   crossAxisAlignment: CrossAxisAlignment.stretch,
                   children: [
                     Container(
                       child: Padding(
                         padding: EdgeInsets.only(left: YBTextStyle.adapterSize20),
                         child: Row(
                           mainAxisAlignment: MainAxisAlignment.start,
                           crossAxisAlignment: CrossAxisAlignment.center,
                           children: [
                             Container(
                               child: InkWell(
                                 child: _select == false?Image.asset(YBImageStyle.getImagePath("login_default")):Image.asset(YBImageStyle.getImagePath("login_selected")),
                                 onTap: () async {
                                   setState(() {
                                     _select = !_select;
                                   });
                                 },
                               ),
                             ),
                             Container(
                               width: YBTextStyle.adapterSize5,
                             ),
                             Container(
                               child: RichText(
                                 text:TextSpan(
                                   style: YBTextStyle.homeSmallSubText,
                                   children:<InlineSpan>[
                                     TextSpan(
                                       text: YBChineseText.woYiYueDuBingTongYiTitle,
                                       style: YBTextStyle.logincolor383A3D13Light,
                                     ),
                                     TextSpan(
                                         text: YBChineseText.workTaiShangJiKuManangerTitle,
                                         style: YBTextStyle.login2D69E013light,
                                         recognizer: TapGestureRecognizer()..onTap = (){
                                           if (sysCode.contains('xg_newyijiwang')) {
                                             YBApplication.router.navigateTo(context,
                                                 "/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage/workTaiMiShuShangJiManangerIdeaYiJiPage");
                                           }else if (sysCode.contains("xg_jinrilvsi")){
                                             YBApplication.router.navigateTo(context,
                                                 "/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage/workTaiMiShuShangJiManangerIdeaLvSiPage");
                                           }
                                         }
                                     ),
                                   ],
                                 ),
                               ),
                             ),
                           ],
                         ),
                       ),
                     ),
                     Container(
                       height: YBTextStyle.adapterSize6,
                     ),
                     Container(
                       height: YBTextStyle.adapterSize26,
                       color: YBColor.common2D69E0,
                       alignment: Alignment.centerLeft,
                       child:Consumer<YBGongGongShengYuNumberProvider>(
                           builder: (context,dataList,child){
                             return Padding(
                               padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                               child:  Text(
                                 "${YBChineseText.workTaiTodayShengYuShangJiKuTitle}${dataList.todayShengYuNumberStr}次",
                                 style: YBTextStyle.TextStyleA9AEB813,
                               ),
                             );
                           }
                       ),
                     ),
                     Container(
                       height: YBTextStyle.adapterSize15,
                     ),
                     Container(
                       height: YBTextStyle.adapterSize44,
                       child:Consumer<YBGongGongQiangDuoProvider>(builder:(context,qiangduoInfo,child){
                         return  Padding(
                           padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                           child: MaterialButton(
                               shape: RoundedRectangleBorder(
                                 side: BorderSide.none,
                                 borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize8)),
                               ),
                               color: YBColor.commonThemeColor,
                               child: Text(YBChineseText.workTaiHuoQuShangJiTitle,style: YBTextStyle.xieGangQingNianTuiGuangYuanBtnText,),
                               onPressed:(){
                                 if (_select == false) {
                                   qiangduoInfo.getGongGongYouXuanDataList(
                                       sysCode, requestCode);
                                 }
                               }),
                         );
                       }),
                     ),
                     Container(
                       height: YBTextStyle.adapterSize15,
                     ),
                   ],
                 );
               }
               String createTimeStr;
               if (youXuanInfo.gongGongYouXuanModel.requestAssignRecordList != null) {
                 YBGongGongCreateTimeModel createTimeModel = youXuanInfo.gongGongYouXuanModel.requestAssignRecordList.last;
                 createTimeStr = createTimeModel.createTime;
               }
               return Column(
                 mainAxisAlignment: MainAxisAlignment.start,
                 crossAxisAlignment: CrossAxisAlignment.stretch,
                 children: [
                    Expanded(
                      child: CustomScrollView(
                        slivers: <Widget>[
                          SliverToBoxAdapter(
                              child: Container(
                                child: Column(
                                  children: [
                                    Container(
                                      color:YBColor.white,
                                      child: Padding(
                                        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                        child: Column(
                                          children: [
                                            Container(
                                              height: YBTextStyle.adapterSize20,
                                            ),
                                            Container(
                                              child: Row(
                                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                crossAxisAlignment: CrossAxisAlignment.center,
                                                children: [
                                                  Container(
                                                    child: Text(
                                                      createTimeStr??"",
                                                      style: YBTextStyle.TextStyle1B1C1F15Medium,
                                                    ),
                                                  ),
                                                  Container(
                                                    child: Text(
                                                      "${youXuanInfo.gongGongYouXuanModel.request.provinceName}-${youXuanInfo.gongGongYouXuanModel.request.cityName}"??"",
                                                      style: YBTextStyle.TextStyle6E737A13,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                            Container(
                                              height: YBTextStyle.adapterSize16,
                                            ),
                                            Container(
                                              child: Row(
                                                children: [
                                                  Container(
                                                    child: Image.asset(YBImageStyle.getImagePath('BLBBusinessOppoManager_phonr')),
                                                  ),
                                                  Container(
                                                    width: YBTextStyle.adapterSize5,
                                                  ),
                                                  Container(
                                                    child: Text(
                                                      youXuanInfo.gongGongYouXuanModel.linkPhone??'',
                                                      style: YBTextStyle.TextStyle6E737A13,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                            Container(
                                              height: YBTextStyle.adapterSize16,
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                    Container(
                                      height: YBTextStyle.adapterSize8,
                                    ),
                                    Container(
                                      color: YBColor.white,
                                      child: Padding(
                                        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                        child: Column(
                                          mainAxisAlignment: MainAxisAlignment.start,
                                          crossAxisAlignment: CrossAxisAlignment.stretch,
                                          children: [
                                            Container(
                                              child: Text(
                                                YBChineseText.workTaiXuQiuNeiRongTitle,
                                                style: YBTextStyle.TextStyle1B1C1F15Medium,
                                              ),
                                            ),
                                            Container(
                                              height: YBTextStyle.adapterSize15,
                                            ),
                                            Container(
                                              child: Text(
                                                youXuanInfo.gongGongYouXuanModel.request.requestServiceDesc??"",
                                                style: YBTextStyle.TextStyle6E737A13,
                                              ),
                                            ),
                                            Container(
                                              height: YBTextStyle.adapterSize15,
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                    Container(
                                      height: YBTextStyle.adapterSize8,
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          SliverToBoxAdapter(
                              child: Container(
                                color:YBColor.white,
                                child: Padding(
                                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize15),
                                  child: Text(
                                    YBChineseText.workTaiMishuDetailliuzhuanJiluTitle,
                                    style: YBTextStyle.TextStyle1B1C1F15Medium,
                                  ),
                                ),
                              ),
                            ),
                          SliverList(
                              delegate:SliverChildBuilderDelegate((_,int index){
                                YBGongGongCreateTimeModel createTimeModel = youXuanInfo.gongGongYouXuanModel.requestAssignRecordList[index];
                                return YBMiShuTongListDetailSubPage(numberStr: (index + 1).toString(),timeStr: createTimeModel.createTime,);
                              },
                                  childCount: youXuanInfo.gongGongYouXuanModel.requestAssignRecordList.length
                              ),
                            ),
                        ],
                      ),
                    ),
                    Container(
                      child: bottomWidget,
                    ),
                  ],
               );
             }
          ),
        ),
      ),
    );
  }
}


